<?php
/***
* @version $Id: help.php 336 2007-01-23 08:12:56Z flexiondotorg $
* @copyright (c) 2006 - 2007 Flexion.Org
*            (c) 2004 - 2005 markus_petrux < phpbb.mods@phpmix.com > (Markus) http://www.phpmix.com
*            (c) 2004 - 2005 Thoul thoul@users.sourceforge.net http://darkmods.sourceforge.net
*            (c) 2004 - 2005 Project Minerva
*            (c) 2001 - 2006 phpBB Group
* @license   http://opensource.org/licenses/gpl-license.php GNU Public License
***/

define('IN_R3BORN', true);
$root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'),	1);
include($root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_HELP);
init_userprefs($userdata);
//
// End session management
//

$default_lang = get_default_lang('help_faq.' . $phpEx);

// Get the core Help files.
$allmodes = array();
$allmodes['faq'] 	= array('help_file' => $root_path . 'language/lang_' . $default_lang . '/help_faq.' . $phpEx,
							'l_title' => $lang['FAQ'],
							'mode' => 'faq');
$allmodes['bbcode'] = array('help_file' => $root_path . 'language/lang_' . $default_lang . '/help_bbcode.' . $phpEx,
							'l_title' => $lang['BBCode_guide'],
							'mode' => 'bbcode');

// Get any help files from modules with a 'help' hook
loadHooks(getHooks('help'));
$hooks->execute(init_help);

// Set vars to prevent naughtiness
$help = array();

if( isset($_GET['mode']) )
{
	if (file_exists($allmodes[$_GET['mode']]['help_file']))
	{
		include($allmodes[$_GET['mode']]['help_file']);
		$l_title = $allmodes[$_GET['mode']]['l_title'];
		$mode = $allmodes[$_GET['mode']]['mode'];
	}
	else
	{
		include($allmodes['faq']['help_file']);
		$l_title = $allmodes['faq']['l_title'];
		$mode = $allmodes['faq']['mode'];
	}
}
else
{
	include($allmodes['faq']['help_file']);
	$l_title = $allmodes['faq']['l_title'];
	$mode = $allmodes['faq']['mode'];
}

//
// Pull the array data from the lang pack
//
$j = 0;
$counter = 0;
$counter_2 = 0;
$help_block = array();
$help_block_titles = array();

for($i = 0; $i < count($help); $i++)
{
	if( $help[$i][0] != '--' )
	{
		$help_block[$j][$counter]['id'] = $counter_2;
		$help_block[$j][$counter]['question'] = $help[$i][0];
		$help_block[$j][$counter]['answer'] = $help[$i][1];

		$counter++;
		$counter_2++;
	}
	else
	{
		$j = ( $counter != 0 ) ? $j + 1 : 0;

		$help_block_titles[$j] = $help[$i][1];

		$counter = 0;
	}
}

page_header($l_title);

### R3-born - ADD (DHTML Collapsible Help)
#
$template->set_filenames(array(
	'body' => (isset($_GET['dhtml']) && $_GET['dhtml'] == 'no' ? 'help_body.tpl' : 'help_dhtml.tpl'))
);
#
### R3-born - END ADD

### R3-born - ADD (Custom Help Page Links)
#
$template->assign_block_vars('other_help', array(
	'L_OTHER_HELP_TITLE' => $lang['Other_help'])
);

$allmodes_first_pass = TRUE;

reset($allmodes);
while ( list( $key, $val) = each( $allmodes ) )
{
	if( $allmodes_first_pass )
	{
		$divider  = '';
	}
	else
	{
		$divider = ' | ';
	}

	if( $mode != $key )
	{
		$allmodes_first_pass = FALSE;

		$template->assign_block_vars('other_help.links', array(
			'U_OTHER_HELP' => append_sid("help.$phpEx?mode=" . $val['mode'], true),
			'OTHER_HELP_NAME' => $val['l_title'],
			'DIVIDER' => $divider)
		);
	}
}
#
### END ADD

$template->assign_vars(array(
	'U_HELP_JS' => $root_path . 'javascript/help.js',
	'L_CHELP_NOSCRIPT' => sprintf($lang['dhtml_help_noscript'], ('<a href="'.append_sid("help.$phpEx?dhtml=no".(isset($_GET['mode']) ? '&amp;mode='.$_GET['mode'] : '')).'">'), '</a>'),
	'L_HELP_TITLE' => $l_title,
	'L_BACK_TO_TOP' => $lang['Back_to_top'])
);

$help_blocks = count($help_block);

for($i = 0; $i < $help_blocks; $i++)
{
	if( count($help_block[$i]) )
	{
		$template->assign_block_vars('help_block', array(
			'BLOCK_TITLE' => $help_block_titles[$i])
		);

		$template->assign_block_vars('help_block_link', array(
			'BLOCK_TITLE' => $help_block_titles[$i])
		);

		for($j = 0; $j < count($help_block[$i]); $j++)
		{
			$row_class = ( !($j % 2) ) ? 'row1' : 'row2';

			$template->assign_block_vars('help_block.help_row', array(
				'ROW_CLASS' => $row_class,
				'HELP_QUESTION' => $help_block[$i][$j]['question'],
				'HELP_ANSWER' => $help_block[$i][$j]['answer'],
				'U_HELP_ID' => $help_block[$i][$j]['id'])
			);

			$template->assign_block_vars('help_block_link.help_row_link', array(
				'ROW_CLASS' => $row_class,
				'HELP_LINK' => $help_block[$i][$j]['question'],

				'U_HELP_LINK' => '#' . $help_block[$i][$j]['id'])
			);
		}
	}
}

$template->pparse('body');

page_footer();

?>